﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using Hangjing.Model;
using Hangjing.SQLServerDAL;
using Hangjing.Common;

/// <summary>
/// 订单详细
/// </summary>
public partial class AndroidAPI_shop_GetOrderDetailByOrderId : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();

        string orderid = HjNetHelper.GetPostParam("orderid");

        Custorder dal = new Custorder();
        Foodlist orderfood_bll = new Foodlist();

        CustorderInfo info = new CustorderInfo();
        IList<CustorderInfo> list = dal.GetListFix(1, 1, " custorder.orderid='" + orderid + "'", "OrderDateTime", 1);


        StringBuilder orderjson = new StringBuilder();

        if (list != null && list.Count > 0)
        {
            info = list[0];
        }

        if (info != null)
        {
            orderjson.Append("{\"totalmoney\":\"" + info.OrderSums.ToString("0.0") + "\",\"phone\":\"" + info.OrderComm + "\",\"SentTime\":\"" + info.OrderDateTime + "\",\"state\":\"" + info.OrderStatus.ToString() + "\",\"userid\":\"" + info.UserId.ToString() + "\",\"foodinorderString\":\"\",\"list\":[");
        }

        IList<FoodlistInfo> food_list = orderfood_bll.GetList(1000, 1, " orderid='" + orderid + "'", "Unid", 1);

        foreach (FoodlistInfo finfo in food_list)
        {
            orderjson.Append("{\"count\":" + finfo.FCounts.ToString() + ",\"id\":\"" + finfo.FoodUnid.ToString() + "\",\"price\":" + finfo.FoodPrice.ToString("0.0") + ",\"name\":\"" + finfo.FoodName + "\"},");
        }
        orderjson.Append("],");

        orderjson.Append("\"shopname\":\"" + info.TogoName + "\",\"people\":1,\"addtime\":\"" + info.OrderDateTime.ToString("yyyy-MM-dd HH:mm:ss") + "\",\"username\":\"" + info.OrderRcver + "\",");
        orderjson.Append("\"shopid\":\"" + info.TogoId.ToString() + "\",\"address\":\"" + info.AddressText + "\",\"Packagefree\":\"" + 0 + "\",\"sentmoney\":\"" + info.SendFee + "\",\"orderid\":\"" + info.orderid + "\",\"realname\":\"" + info.OrderRcver + "\",\"note\":\"" + info.OrderAttach + "\",\"shopaddress\":\"" + info.TogoAddress + "\",\"shoptel\":\"" + info.TogoTel + "\"");
        orderjson.Append(",\"PayMode\":\"" + info.paymode + "\"");
        orderjson.Append(",\"OrderTotal\":\"" + info.shopdiscountmoney.ToString() + "\"");
        orderjson.Append(",\"oldprice\":\"" + info.OldPrice.ToString() + "\"");
        orderjson.Append(",\"Advance\":\"" + info.Advance.ToString() + "\"");
        orderjson.Append(",\"eattype\":\"" + info.ReveInt2 + "\"");
        orderjson.Append(",\"people\":\"" + info.ReveInt1 + "\"");
        orderjson.Append(",\"SystemUserId\":\"" + info.SystemUserId + "\"");


        orderjson.Append(",\"sendstate\":\"" + info.sendstate + "\"");
        orderjson.Append(",\"paystate\":\"" + info.paystate + "\"");
        orderjson.Append(",\"paymoney\":\"" + info.paymoney + "\"");
        orderjson.Append(",\"IsShopSet\":\"" + info.IsShopSet + "\"");
        orderjson.Append(",\"shoptel\":\"" + info.TogoTel + "\"");
        orderjson.Append(",\"SentTime\":\"" + info.SendTime + "\"");

        orderjson.Append("}");

        Response.Write(orderjson.ToString().Replace(",],", "],"));
        Response.End();
    }
}
